package models;

import java.util.List;

import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Query;

public class InboxMessage extends Model {
	@Id(Generator.AUTO_INCREMENT)
	public Long id;
	
	public User owner;
	
	public Message message;

	public Boolean readed;
	
	public Boolean deleted;
	
	public InboxMessage(User owner, Message message) {
		this.owner = owner;
		this.message = message;
		this.readed = Boolean.FALSE;
		this.deleted = Boolean.FALSE;
	}
	
	public InboxMessage(User owner, Message message, Boolean readed, Boolean deleted) {
		this.owner = owner;
		this.message = message;
		this.readed = readed;
		this.deleted = deleted;
	}
	
	public static Query<InboxMessage> all() {
		return all(InboxMessage.class);
	}
	
	public static Query<InboxMessage> findReceived(User to) {
		return all().filter("owner", to);
	}
	
	public static int countReceived(User to) {
		return findReceived(to).count();
	}
	
	public static InboxMessage getReceived(Long id, User to) {
		return findReceived(to).filter("id", id).get();
	}
	
	public static List<InboxMessage> paginate(Query<InboxMessage> query, int offset, int limit) {
		return query.fetch(limit, offset);
	}
}
